import 'package:favourcate/core/model/meal_model.dart';
import 'package:favourcate/core/services/meal_request.dart';
import 'package:favourcate/core/viewmodel/filter_view_model.dart';
import 'package:flutter/material.dart';

class MealViewModel extends ChangeNotifier {
  List<GLMealModel> _meals = [];
  late GLFilterViewModel _filterStore;

  List<GLMealModel> get meals {
    return _meals.where((meal) {
      // 过滤
      if (_filterStore.isGlutenFree && !meal.isGlutenFree) return false;
      if (_filterStore.isLactoseFree && !meal.isLactoseFree) return false; 
      if (_filterStore.isVegetarial && !meal.isVegetarian) return false; 
      if (_filterStore.isVegan && !meal.isVegan) return false; 
      return true;
    }).toList();
  }

  void updateFilters(GLFilterViewModel filterStore) {
    _filterStore = filterStore;
  }

  MealViewModel() {
    GLMealRequest.getMealData().then((value) {
      _meals = value;
      notifyListeners();
    });
  }
}